import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import { Table, Spin, Form, Row, Col, Input, Button, Dropdown, Menu, Icon, Popconfirm, message, Modal, Select, TreeSelect, Checkbox, Tabs, Tag, Popover, Upload } from 'antd'
import _ from 'lodash'

import Ajax from 'lib/Ajax'
import { addConfig } from 'actions/config'
import { getNewTreeData, findRowData, getNameByCode, getArrayByValue, getArrayByKey, confirmDelete, download } from 'lib/fun'
const FormItem = Form.Item;

function createMarkup(html) { return {__html: html}; };
// 新建编辑
class Edit extends Component {
  constructor(props) {
    super(props);
    this.state = {
      feedback: {},
      loading: false
    }
  }

  componentDidMount(){
    // this.loadTag();
    // this.loadDic();
  }

  componentWillReceiveProps(nextProps){
    if(!nextProps.visible){
    }else{
      if(nextProps.feedbackId&&!this.props.visible){
        // &&nextProps.newsId != this.props.newsId
        this.loadData(nextProps.feedbackId);
      }
    }
  }

  loadData = (id)=>{
    var self = this;
    self.setState({
      loading: true,
      feedback: {}
    });
    Ajax({
      url: '/feedback/get',
      data: {
        id: id
      },
      success: function(data){
        self.setState({
          loading: false,
          feedback: data
        });
      },
      error: function(error){
        self.setState({
          loading: false
        });
        message.error(error);
      }
    });
  }

  render() {
    const { visible, onClose, common } = this.props;
    const { feedback } = this.state;
    const newsTypes = common.newsTypeEn||[];
    const getNewsTypeName = (text)=>{
      var find = _.find(newsTypes, (item)=>{
        return item.code == text
      })
      if(find){
        return find.mean
      }else{
        return ""
      }
    }
    const formItemLayout = {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
    };
    const formItemLayout2 = {
      labelCol: { span: 5 },
      wrapperCol: { span: 19 },
    };
    return (<div>
            <Modal 
              title="用户反馈详情"
              visible={visible}
              onOk={ onClose } 
              onCancel={ onClose }
              footer=""
              width="920px"
            >
              <Spin spinning={this.state.loading}>
                <div className="news" style={{minHeight: 200}}>
                  <Row gutter={20}>
                    <Col span={12}>
                      <FormItem {...formItemLayout} label="标题">
                        { feedback.title }
                      </FormItem>
                    </Col>
                    <Col span={12}>
                      <FormItem {...formItemLayout} label="姓名">
                        { feedback.name||"-" }
                      </FormItem>
                    </Col>
                    <Col span={12}>
                      <FormItem {...formItemLayout} label="联系方式">
                        { feedback.tel||'-' }
                      </FormItem>
                    </Col>
                    <Col span={12}>
                      <FormItem {...formItemLayout} label="所在单位">
                        { feedback.company||'-' }
                      </FormItem>
                    </Col>
                    <Col span={24}>
                      <FormItem {...formItemLayout2} label="详细描述">
                        { feedback.content||'-' }
                      </FormItem>
                    </Col>
                  </Row>
                </div>
              </Spin>
            </Modal>
            
            </div>);
  }
}

function mapStateToProps(state) {
  return {
    common: state.common
  }
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators({ addConfig }, dispatch)
}

module.exports = connect(mapStateToProps)(Edit);
